//
//  CHEvaluationListCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/4/14.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHEvaluationListCell.h"
#import "CHStarView.h"
#import "CHPhotosView.h"
@interface CHEvaluationListCell()




{
    
    UILabel *titleLabel;
    UIImageView *iconImgView;
    UILabel *phoneLabel;
    CHStarView *starView;
//    UILabel *repairStypeLabel;
    UILabel *contentLabel;
    UIImageView *picImgView;
    UILabel *timeLabel;
    CHPhotosView *photosView;
    
}

@property (nonatomic ,strong) NSMutableArray *views;

@end

@implementation CHEvaluationListCell


-(NSMutableArray *)views{
    
    
    if (!_views) {
        _views = [NSMutableArray array];
    }
    return _views;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype)cellForTableView:(UITableView *)tableView{
    
    static NSString *ID = @"CHEvaluationListCell";
    
    CHEvaluationListCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[CHEvaluationListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self buildUI];
        
    }
    return self;
    
    
}

-(void)buildUI{
    
    titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:titleLabel];
    
    iconImgView = [[UIImageView alloc] init];
    iconImgView.image = [UIImage imageNamed:@"car_icon"];
    [self.contentView addSubview:iconImgView];
    
    phoneLabel = [[UILabel alloc] init];
    phoneLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:phoneLabel];
    
    starView = [[CHStarView alloc] init];
    [self.contentView addSubview:starView];
    
    photosView = [[CHPhotosView alloc] init];
    [self.contentView addSubview:photosView];
    
    
    
    contentLabel = [[UILabel alloc] init];
    contentLabel.numberOfLines = 0;
//    contentLabel.backgroundColor = [UIColor redColor];
    contentLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:contentLabel];
    
    timeLabel = [[UILabel alloc] init];
    timeLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:1.0f];
    timeLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:timeLabel];
    
}


-(void)setEvaluationFrm:(CHEvaluationListFrame *)evaluationFrm{
    
    _evaluationFrm = evaluationFrm;
    // 1. 给子控件设置数据
    [self settingData];
    
    // 2. 根据子控件里面的数据，计算并且设置子控件frame
    [self settingFrame];
    
}


-(void)settingData{
    
    CHEvaluationListModel *model = self.evaluationFrm.model;
    titleLabel.text = model.company;
    phoneLabel.text = [model.mobilephone stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    starView.starNum = [model.evaluatetotle intValue];
    photosView.pic_urls = [model.imgrepairafter componentsSeparatedByString:@","];
    contentLabel.text = model.evaluatetotledetails;
    timeLabel.text = model.evaluatetime;
    
    
}




-(void)settingFrame{
    
    titleLabel.frame = self.evaluationFrm.titleFrm;
    iconImgView.frame = self.evaluationFrm.iconFrm;
    phoneLabel.frame = self.evaluationFrm.phoneFrm;
    starView.frame = self.evaluationFrm.starFrm;
    photosView.frame = self.evaluationFrm.photosViewFrm;
    contentLabel.frame = self.evaluationFrm.contentTextFrm;
    timeLabel.frame = self.evaluationFrm.timeFrm;
    
}









@end
